Expand description

Export telemetry signals to stdout.

Examples

{
use opentelemetry::metrics::MeterProvider as _;
use opentelemetry::trace::{Span, Tracer, TracerProvider as _};
use opentelemetry::{Context, KeyValue};

use opentelemetry_sdk::metrics::{MeterProvider, PeriodicReader};
use opentelemetry_sdk::runtime;
use opentelemetry_sdk::trace::TracerProvider;

fn init_trace() -> TracerProvider {
    let exporter = opentelemetry_stdout::SpanExporter::default();
    TracerProvider::builder()
        .with_simple_exporter(exporter)
        .build()
}

fn init_metrics() -> MeterProvider {
    let exporter = opentelemetry_stdout::MetricsExporter::default();
    let reader = PeriodicReader::builder(exporter, runtime::Tokio).build();
    MeterProvider::builder().with_reader(reader).build()
}

let tracer_provider = init_trace();
let meter_provider = init_metrics();

// recorded traces and metrics will now be sent to stdout:

// {"resourceMetrics":{"resource":{"attributes":[{"key":"service.name","value":{"str..
// {"resourceSpans":[{"resource":{"attributes":[{"key":"service.name","value":{"stri..